package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.constant.PageResult;
import com.itheima.constant.QueryPageBean;
import com.itheima.dao.PermissionDao;
import com.itheima.domain.CheckItem;
import com.itheima.domain.Permission;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/10/14 19:22
 */
@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permissionDao;

    //分页查询;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer page = queryPageBean.getCurrentPage();
        Integer size = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(page, size);
        Page<Permission> checkItems = permissionDao.findByCondition(queryString);
        long total = checkItems.getTotal();
        List<Permission> rows = checkItems.getResult();
        return new PageResult(total, rows);
    }

    //添加数据;
    @Override
    public void add(Permission permission) {
        permissionDao.add(permission);
    }

    //删除数据;
    @Override
    public void deleteByid(Integer id) {
        permissionDao.deleteByid(id);
    }

    //编辑的数据回显;
    @Override
    public Permission findByid(Integer id) {
        Permission permission = permissionDao.findByid(id);
        return permission;
    }

    //编辑数据
    @Override
    public void update(Permission permission) {
        permissionDao.update(permission);
    }

    //查询全部;
    @Override
    public List<Permission> findAll() {
        return permissionDao.findAll();
    }
}
